//<script type="text/javascript">
    //<![CDATA[
$(document).ready(function()
{
    $.tablesorter.addParser({
        id: 'classimage',
        is: function(s)
        {
            return false;
        },
        type: 'text',
        format: function(s)
        {
            //alert(s);
            var matchs = s.match(/\/images\/class\/(.*?)"/);
            return matchs[1];
        }

    });

    $("#<?php echo $name ?>Table").tablesorter({
        sortList: [[0,0]],
        //sortForce: [[0,0]],
        cssAsc: "headerUp ui-state-active",
        cssDesc: "headerDown ui-state-active",
        cssHeader: "headerUpDown",
        textExtraction: function(node) {
            // extract data from markup and return it
            if (node.childNodes[1] && node.childNodes[1].innerHTML)
                return node.childNodes[1].innerHTML;
            else
                return node.innerHTML;
        }
    });

    $("#<?php echo $name ?>Table").bind(
        "sortStart",
        function()
        {
            $(".<?php echo $name ?>data").remove();
            $('#<?php echo $name ?>Table').removeData('content_old');
            $("#"+<?php echo $name ?>Table_content_show+"").children().removeClass('ui-state-active');
            $("#"+<?php echo $name ?>Table_content_show+"").children().addClass('ui-widget-content');
        });

    $("#<?php echo $name ?>Table").bind(
        "sortEnd",
        function()
        {
            $(".headerUpDown > span").removeClass("ui-icon-triangle-2-n-s").addClass("ui-icon-triangle-2-n-s");
            $(".headerUp > span").addClass("ui-icon-triangle-1-n").removeClass("ui-icon-triangle-1-s").removeClass("ui-icon-triangle-2-n-s");
            $(".headerDown > span").addClass("ui-icon-triangle-1-s").removeClass("ui-icon-triangle-1-n").removeClass("ui-icon-triangle-2-n-s");
        });
        
    var <?php echo $name ?>Table_content_show;
    $("#<?php echo $name ?>Table tr").click(
        function()
        {
            if (<?php echo $name ?>Table_content_show != $(this).attr("id"))
            {
                <?php echo $name ?>Table_content_show = $(this).attr("id");
                $.ajax({
                    method: "get",
                    url: "<?php echo url_for('ajax/'.$name) ?>",
                    data: "p="+<?php echo $name ?>Table_content_show.replace("<?php echo $name ?>", "")+"&r=1",
                    beforeSend: function()
                    {
                        $("#"+<?php echo $name ?>Table_content_show+"").after('<tr id="ajaxContainerTr"><td class="ui-widget-content" colspan="8" id="ajaxContainerTd"></td></tr>');
                        $('#ajaxLoader').appendTo("#ajaxContainerTd").css({
                            position: "relative",
                            top: "0px",
                            left: "0px"
                        });
                        $("#ajaxContainerTr").hide();
                        $("#ajaxContainerTr").fadeIn("fast");
                    },
                    success: function(html)
                    { //so, if data is retrieved, store it in html
                        $(".<?php echo $name ?>data").remove();

                        if($('#<?php echo $name ?>Table').data('content_old') == <?php echo $name ?>Table_content_show)
                        {
                            $('#<?php echo $name ?>Table').removeData('content_old');
                        }
                        else
                        {
                            $('#<?php echo $name ?>Table').data('content_old', <?php echo $name ?>Table_content_show);
                            $('#<?php echo $name ?>Table').data('content', $("."+<?php echo $name ?>Table_content_show+"").html());
                        }
                        $("#ajaxContainerTr").slideUp("fast", function () { $("#ajaxContainerTr").remove(); });
                        $("#ajaxLoader").appendTo("body").css({
                            position: "relative",
                            top: "0px",
                            left: "0px"
                        });

                        //$("#"+<?php echo $name ?>Table_content_show+"").hide(); //animation
                        $("#"+<?php echo $name ?>Table_content_show+"").after(html); //show the html inside .content div
                        docReady('#tabsAjax');
                        setupLinks(".<?php echo $name ?>data");
                        $("#"+<?php echo $name ?>Table_content_show+"").children().addClass('ui-state-active').removeClass('ui-widget-content');
                        $(".<?php echo $name ?>data").hide();
                        $(".<?php echo $name ?>slide").hide();
                        $(".<?php echo $name ?>data").show();

                        //$("#"+pointsTable_content_show+"").fadeIn("slow", function() { $("#filterDialog").dialog('option', 'position', [left,top]); } ); //animation
                        $(".<?php echo $name ?>slide").slideDown("slow", function() {
                            //$('#tabs3 > div').equalHeights();
                        } );
                    }
                }); //close $.ajax(
            }
            $('#<?php echo $name ?>Table tbody > tr').children().removeClass('ui-state-active').addClass('ui-widget-content');
            if ($(".<?php echo $name ?>slide").is(":visible"))
            {
                $(".<?php echo $name ?>slide").slideUp("fast", <?php echo $name ?>TablePartTwo)
            }
            else if (<?php echo $name ?>Table_content_show == $(this).attr("id"))
            {
                $(".<?php echo $name ?>data").show();
                $(".<?php echo $name ?>slide").slideDown("slow", <?php echo $name ?>TablePartTwo)
                $("#"+<?php echo $name ?>Table_content_show+"").children().addClass('ui-state-active').removeClass('ui-widget-content');
            }
        }
        );

    function <?php echo $name ?>TablePartTwo()
    {
        if (!$(".<?php echo $name ?>slide").is(":visible"))
        {
            $(".<?php echo $name ?>data").hide();
        }
    }
});
    //]]>
//</script>